<?php

class GridController extends AmpController
{

  protected function action_index()
  {
  }

  protected function action_data()
  {
    $count = $this->db->query('SELECT COUNT({User.id}) AS total from {User}')->fetch();
    $pager = new Pager($count['total'], $this->form->get('rows'), $this->form->get('page'), false);
    $users = $this->db->from('User')->orderBy($this->form->get('sidx').' '.$this->form->get('sord'))->offset($pager->getCurrentOffset())->limit($this->form->get('rows'))->find();
    
    $rows = array();
    foreach ($users as $user) {
      $rows[] = $user->getAll();
    }
    
    $this->response->set('rows', $rows);
    $this->response->set('page', $pager->getCurrentPage());
    $this->response->set('total', $pager->getTotalPages());
    $this->response->set('records', $pager->getCount());
    
    return false;
  }

}

?>